package org.sqp.wechat;

import org.sqp.wechat.client.WechatWebClient;

import java.util.Scanner;

/**
 * @author sunqipeng
 * @date 2019/1/7
 */
public class WechatReadApplication {
    public static void main(String[] args) {
        String vid = "";
        String skey = "";
        if (args != null && args.length > 0) {
            vid = args[0];
            skey = args[1];
        }
        WechatWebClient wechatWebClient = new WechatWebClient(skey,vid);

        System.out.println("请输入指令进行操作，直接输入书名进行搜索，输入 d-{bookId}进行下载 ");
        for (;;){
            String input = waitForInput();
            if (input.equalsIgnoreCase("exit")){
                System.exit(0);
            }else if (input.startsWith("d-")){
                String bookIds = input.replace("d-","");
                for (String bookId:bookIds.split("-")){
                    wechatWebClient.download(Integer.parseInt(bookId));
                }
            }else{
                wechatWebClient.search(input);
            }
        }
    }

    static String waitForInput(){
        System.out.print(">:");
        Scanner scanner = new Scanner(System.in);
        return scanner.next();
    }
}
